<script type="text/javascript" src="http://cdn.biodeep.cn/vendor/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.biodeep.cn/vendor/aes-js/aes.js"></script>
<script type="text/javascript">

    $.get("{index/aes_message}", function(message) {
        if (message.code == 0) {

            var key = message.info.key;
            var msg = new String(Base64Decode(message.info.msg));
            var iv  = msg.substr(0, 16);

            console.log(msg)
            console.log(iv);
            console.log(message);

            key = aesjs.utils.utf8.stringASCIIBytes(key);
            iv  = aesjs.utils.utf8.stringASCIIBytes(iv);
            msg = msg.substr(16);

            var encryptedBytes = aesjs.utils.utf8.stringASCIIBytes(msg);

            console.log(msg);

            var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
            var decryptedBytes = aesCbc.decrypt(encryptedBytes);

            // Convert our bytes back into text
            var decryptedText = aesjs.utils.utf8.bytesMessage(decryptedBytes);
            console.log("[" + decryptedText + "]");

        } else {
            console.error(message);
        }
    });

    function Base64Decode(str, encoding = 'utf-8') {
        var bytes = aesjs.utils.utf8.stringASCIIBytes(str);
        var buffer = new Uint8Array(bytes);
        return new (TextDecoder || TextDecoderLite)(encoding).decode(buffer);
    }

/*
    // An example 128-bit key
    var key = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];

    // The initialization vector (must be 16 bytes)
    var iv = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36];

    // Convert text to bytes (text must be a multiple of 16 bytes)
    var text = 'TextMustBe16Byte2';
    var textBytes = aesjs.utils.utf8.msgEnsure16Bytes(text);

    var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
    var encryptedBytes = aesCbc.encrypt(textBytes);

    // To print or store the binary data, you may convert it to hex
    var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
    console.log(encryptedHex);
    // "104fb073f9a131f2cab49184bb864ca2"

    // When ready to decrypt the hex string, convert it back to bytes
    var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);

    // The cipher-block chaining mode of operation maintains internal
    // state, so to decrypt a new instance must be instantiated.
    var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
    var decryptedBytes = aesCbc.decrypt(encryptedBytes);

    // Convert our bytes back into text
    var decryptedText = aesjs.utils.utf8.bytesMessage(decryptedBytes);
    console.log("[" + decryptedText + "]");
// "TextMustBe16Byte"
*/
</script>